package com.zy.datareceiver;

import com.zy.datareceiver.binsess.decode.service.DBSaveThread;
import com.zy.datareceiver.binsess.decode.service.ObjectStatusMonitoring;
import com.zy.datareceiver.binsess.decode.service.StorageTaskService;
import com.zy.datareceiver.binsess.stomp.service.StompMessageService;
import com.zy.datareceiver.binsess.warning.service.impl.WarningDataTask;
import com.zy.datareceiver.core.cast.ConCast;
import com.zy.datareceiver.core.common.SpringApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.concurrent.Executor;

@SpringBootApplication
@EnableAsync
@EnableScheduling
@MapperScan("com.zy.datareceiver.binsess.*.mapper")
public class Application {
    private static final Logger log = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        doExecutor();
    }
    public static void doExecutor(){
        Executor executor = SpringApplicationContext.getBean("taskExecutor",Executor.class);

        for (int i = 0; i < ConCast.Thread.STOMP; i++) {
            executor.execute(new StompMessageService());//数据推送线程
        }
        for (int i = 0; i < ConCast.Thread.DECODE; i++) {
            executor.execute(new StorageTaskService());//两个解析线程处理
        }

        executor.execute(new DBSaveThread());//实时数据入库线程
        executor.execute(new WarningDataTask());//预警处理线程
        executor.execute(new ObjectStatusMonitoring());//状态监控线程
    }
}
